home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 38 / Amiga Format CD38 (1999-03-15)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-04].iso / -seriously_amiga- / programming / other / cyberxxxsrc / decoder / txt / decodedviadpcm.c < prev    next >
C/C++ Source or Header  |  1999-02-08  |  4KB  |  170 lines

  1. /*
  2. sc:c/sc opt txt/DecodeDVIADPCM.c
  3. */
  4.  
  5. #include "Decode.h"
  6. #include "ADPCM.h"
  7.  
  8. struct DVIADPCMData {
  9.   short blockCnt;
  10. };
  11.  
  12. /* /// "DecodeDVIADPCMMono()" */
  13. __asm ulong DecodeDVIADPCMMono(REG(a0) uchar *from,
  14.                                REG(a1) short *toL,
  15.                                REG(a2) short *toR,
  16.                                REG(d0) ulong size,
  17.                                REG(a3) struct DVIADPCMData *spec)
  18. {
  19.   long todo=size;
  20.   ulong decoded=0;
  21.  
  22.   ulong blockCnt=spec->blockCnt;
  23.  
  24.   while (todo>0) {
  25.     long valPred;
  26.     long index;
  27.     long step;
  28.     ushort n;
  29.     uchar firstNibble;
  30.  
  31.     valPred=get16pc(from);
  32.     if (valPred & 0x8000) valPred-=0x10000;
  33.     index=*from;
  34.     from+=2;
  35.     if (index>88) index=88;
  36.     step=stepSizeTable[index];
  37.     todo-=4;
  38.     if (todo<=0) {decoded=0; goto dviadpcmMDecode4BitExit;}
  39.  
  40.     *toL++=(uchar)(valPred>>8);
  41.     decoded++;
  42.  
  43.     firstNibble=1;
  44.     for(n=1; n<blockCnt; n++) {
  45.       ulong loNibble, hiNibble;
  46.  
  47.       if (firstNibble) {
  48. /* /// "new style" */
  49.         loNibble=*from++;
  50.         hiNibble=(loNibble>>4) & 0x0f;
  51.         loNibble &= 0x0f;
  52. /* \\\ */
  53. /* /// "old style"
  54.         hiNibble=*from++;
  55.         loNibble=(hiNibble>>4) & 0x0f;
  56.         hiNibble &= 0x0f;
  57. \\\ */
  58.         todo--;
  59.         if (todo<0) goto dviadpcmMDecode4BitExit;
  60.         firstNibble=0;
  61.       } else {
  62.         loNibble=hiNibble;
  63.         firstNibble=1;
  64.       }
  65.       calcDVI(valPred,loNibble,index,step);
  66.       *toL++=valPred;
  67.       decoded++;
  68.     }
  69.   }
  70.  
  71. dviadpcmMDecode4BitExit:
  72.   return decoded;
  73. }
  74. /* \\\ */
  75.  
  76. /* /// "DecodeDVIADPCMStereo()" */
  77. __asm ulong DecodeDVIADPCMStereo(REG(a0) uchar *from,
  78.                                  REG(a1) short *toL,
  79.                                  REG(a2) short *toR,
  80.                                  REG(d0) ulong size,
  81.                                  REG(a3) struct DVIADPCMData *spec)
  82. {
  83.   long todo=size;
  84.   ulong decoded=0;
  85.  
  86.   ulong blockCnt=spec->blockCnt;
  87.  
  88.   while (todo>0) {
  89.     long lValPred, rValPred;
  90.     long lIndex, rIndex;
  91.     long lStep, rStep;
  92.     ushort n;
  93.  
  94.     lValPred=get16pc(from);
  95.     if (lValPred & 0x8000) lValPred-=0x10000;
  96.     lIndex=*from;
  97.     from+=2;
  98.     if (lIndex>88) lIndex=88;
  99.     lStep=stepSizeTable[lIndex];
  100.  
  101.     rValPred=get16pc(from);
  102.     if (rValPred & 0x8000) rValPred-=0x10000;
  103.     rIndex=*from;
  104.     from+=2;
  105.     if (rIndex>88) rIndex=88;
  106.     rStep=stepSizeTable[rIndex];
  107.  
  108.     todo-=8;
  109.     if (todo<=0) {decoded=0; goto dviadpcmSDecode4BitExit;}
  110.  
  111.     *toL++=lValPred;
  112.     *toR++=rValPred;
  113.     decoded++;
  114. /* /// "new style" */
  115.     for (n=1; n<blockCnt; n+=8) {
  116.       ulong lStore, rStore, flag;
  117.       lStore=get32pc(from);
  118.       rStore=get32pc(from);
  119.       todo-=8;
  120.       if (todo<0) goto dviadpcmSDecode4BitExit;
  121.       for (flag=0; flag<8; flag++) {
  122.         ulong nibble;
  123.         nibble=lStore & 0x0f;
  124.         calcDVI(lValPred,nibble,lIndex,lStep);
  125.         *toL++=lValPred;
  126.         nibble=rStore & 0x0f;
  127.         calcDVI(rValPred,nibble,rIndex,rStep);
  128.         *toR++=rValPred;
  129.         decoded++;
  130.         lStore>>=4;
  131.         rStore>>=4;
  132.       }
  133.     }
  134. /* \\\ */
  135. /* /// "old style"
  136.     firstNibble=1;
  137.     for(n=1; n<blockCnt; n++) {
  138.       ulong loNibbleL, hiNibbleL;
  139.       ulong loNibbleR, hiNibbleR;
  140.  
  141.       if (firstNibble) {
  142.         loNibbleL=*from++;
  143.         hiNibbleL=(loNibbleL>>4) & 0x0f;
  144.         loNibbleL &= 0x0f;
  145.         loNibbleR=*from++;
  146.         hiNibbleR=(loNibbleR>>4) & 0x0f;
  147.         loNibbleR &= 0x0f;
  148.         todo--;
  149.         if (todo<0) goto dviadpcmSDecode4BitExit;
  150.         firstNibble=0;
  151.       } else {
  152.         loNibbleL=hiNibbleL;
  153.         loNibbleR=hiNibbleR;
  154.         firstNibble=1;
  155.       }
  156.       calcDVI(lValPred,loNibbleL,lIndex,lStep);
  157.       *toL++=lValPred;
  158.       calcDVI(rValPred,loNibbleR,rIndex,rStep);
  159.       *toR++=rValPred;
  160.       decoded++;
  161.     }
  162. \\\ */
  163.   }
  164.  
  165. dviadpcmSDecode4BitExit:
  166.   return decoded;
  167. }
  168. /* \\\ */
  169.  
  170.